#include "Overtake.h"
#include "turn.h"
#include "Exchange.h"
#include "Debug.h"
#include "VCAN_LED.H" 
#include "PID.h"
#include <math.h>
#include <stdbool.h>


Overtake overtake_flag;
State state, state_last;
extern char flag_PIT;
int Length_Overtake, Length_Overtaking;

uint8 GetImg(uint8 *img)
{
  uint8 length;
  for(int i = 0; i < 80; i++)
  {
    if(img[17*80 + i])  length += 1;
  }
  return length;
}

uint8 get_over_finish(uint8 *img)
{
  for(int i = 15; i <20; i++)   //8-21
  {
    if(img[17*80 + i] != 0)     return 0;
  }
  return 1;
}
void overtake(uint8 *img)
{
  if(overtake_flag.overtake_start)
  { 
     if(get_over_finish(img))
     {
       overtake_flag.overtake_start = 0;
//       led(LED1,LED_ON);
       Speed_Start = (int)control.Speed;
       overtake_flag.OverFinish = 1;
       state = later;
     }
  }

}